function useMousePosition() {
  const [point, setPoint] = useState({ x: 0, y: 0 })

  function savePoint(event: MouseEvent) {
    setPoint({
      x: event.pageX,
      y: event.pageY
    })
  }

  useEffect(() => {
    window.addEventListener('click', savePoint)
    return () => {
      window.removeEventListener('click', savePoint)
    }
  }, [])

  return point
}

export default useMousePosition